<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>更新班级</title>
    <link th:href="@{~/assets/layui/css/layui.css}" rel="stylesheet"/>
</head>
<body style="margin: 10px">
<fieldset class="layui-elem-field">
    <legend>新密码</legend>
    <input type="text" name="newpassword" id="newpassword" class="layui-input" placeholder="新密码" >
    <hr>
    <input type="text" name="newpassword" id="newpassword1" class="layui-input" placeholder="再次确认" >
    <input type="text" name="id" id="id" style="display: none" th:value="${id}">
</fieldset>


<hr>
<div class="layui-input-inline">
    <div class="layui-form-item">
        <button type="button" class="layui-btn" id="push">提交</button>
    </div>
</div>

</body>
<script th:src="@{~/assets/layui/layui.js}"></script>
<script th:src="@{~/assets/jquery.min.js}"></script>
<script>


    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;


    });


    $("#push").click(function () {

        var password = $("#newpassword").val()
        var password1 = $("#newpassword1").val()
        if (password !=password1){
            layer.msg("两次输入不一致", {
                icon: 5
            });
            return false;
        }
        var id = $("#id").val()

        $.ajax({
            type: "post",
            contentType: "application/x-www-form-urlencoded",
            url: "/api/v1/admin/updatepwd",
            data: {
                "id":id,
                "userPassword":password1
            },
            dataType: "json",
            success: function (data) {
                if (data.resultTypeEnum == 200) {
                    layer.msg("修改成功，2s后跳转登录页面", {
                        icon: 1
                    });
                    var count = 2;
                    setTimeout(goIndexPage,1000);
                    function goIndexPage(){
                        count--;
                        if(count <=0){
                            top.location.href = "logout";
                        }else{
                            setTimeout(goIndexPage,1000) //递归调用,自己调用自己
                        }
                    }

                    //关闭父级页面的表格
                }else {
                    layer.msg(data.message, {
                        icon: 5
                    });
                }
            }
        });
    })
</script>
</html>